//
//  YXUICreators.m
//  TASWork
//
//  Created by TAS-Mac on 2018/1/9.
//  Copyright © 2018年 TAS-Mac. All rights reserved.
//

#import "YXUICreators.h"

@implementation YXUICreators
+ (UILabel *)createLabelBgColor:(UIColor *)bgColor
                      textColor:(UIColor *)textColor
                       fontSize:(CGFloat )font
                  textAlignment:(NSTextAlignment)alignment
{
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = bgColor;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByTruncatingTail;
    label.font = [UIFont systemFontOfSize:font];
    label.textColor = textColor;
    label.textAlignment = alignment;
    return label;
}

+ (UIImageView *)createImageView:(UIColor *)bgColor image:(UIImage*)image radius:(CGFloat)radius size:(CGSize)size
{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.userInteractionEnabled = YES;

    if (bgColor) {
        imageView.backgroundColor = bgColor;
    }

    if (image) {
        imageView.image = image;
    }

    if (radius>0) {
        imageView.layer.cornerRadius = radius;
        imageView.layer.masksToBounds = YES;
    }

    if (!CGSizeEqualToSize(size, CGSizeZero)) {
        [imageView setSize:size];
    }

    return imageView;
}

+ (UIButton*)createButton:(id)target action:(SEL)action
                    title:(NSString*)title
                titleSize:(CGFloat)titleSize
    backgroundImageNormal:(UIImage*)backgroundImageNormal
backgroundImageHighlighted:(UIImage*)backgroundImageHighlighted
                   radius:(CGFloat)radius
{
    UIButton *btn = [[UIButton alloc] init];
    if (target && action) [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    if (title) {
        [btn setTitle:title forState:UIControlStateNormal];
    }
    
    if (backgroundImageNormal) {
        [btn setBackgroundImage:backgroundImageNormal forState:UIControlStateNormal];
    }
    
    
    if (backgroundImageHighlighted) {
        [btn setBackgroundImage:backgroundImageHighlighted forState:UIControlStateHighlighted];
    }
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    
    btn.titleLabel.font = [UIFont systemFontOfSize:titleSize];
    if (radius>0) {
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = radius;
    }
    return btn;
}
@end
